package com.translate.web.api.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.param.impl.IdParam;
import com.param.impl.PageParam;
import com.translate.vo.AcademicResourcesVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.translate.web.param.AcademicResourcesUpdateParam;
import com.translate.web.param.AcademicResourcesAddParam;
import com.translate.entity.AcademicResources;
import com.translate.web.service.IAcademicResourcesService;
import com.basic.service.contract.IBaseService;

@RestController
@RequestMapping("academicResources")
public class AcademicResourcesController extends AbstractCommonController<AcademicResources, PageParam> {
	private IAcademicResourcesService service;


	public AcademicResourcesController(IAcademicResourcesService service) {
		this.service = service;
	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated AcademicResourcesAddParam param,
			HttpServletRequest httpServletRequest) {
		int id = this.service.parseInsert(param, AcademicResources.class);

		return ResponseModel.<Integer>success(id);
	}

	@Override
	protected IBaseService<AcademicResources> getBaseService() {
		return this.service;
	}
	
	@PostMapping("/academicResourcesServiceById")
	public ResponseModel<AcademicResourcesVO> academicResourcesServiceById(@RequestBody @Validated IdParam param) {
		
		AcademicResourcesVO articleById = this.service.getArticleById(param.getId(), AcademicResourcesVO.class);
		
		if (null == articleById) {
			return ResponseModel.errorMsg(null, "获取失败");
		}
		
		return ResponseModel.<AcademicResourcesVO>success(articleById);

	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody AcademicResourcesUpdateParam param,
			HttpServletRequest httpServletRequest) {
		int res = this.service.parseUpdate(param, AcademicResources.class);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) AcademicResourcesVO.class;
	}
}